import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { Order } from './order.entity';

/**
 * 订单详情实体类
 */
@Entity('order_details')
export class OrderDetail {
  /**
   * 主键ID
   */
  @PrimaryGeneratedColumn()
  id: number;

  /**
   * 订单ID
   */
  @Column({ name: 'order_id' })
  orderId: number;

  /**
   * 关联的订单
   */
  @ManyToOne(() => Order, order => order.details)
  @JoinColumn({ name: 'order_id' })
  order: Order;

  /**
   * 菜品ID
   */
  @Column({ name: 'dish_id' })
  dishId: number;

  /**
   * 菜品名称
   */
  @Column({ name: 'dish_name', length: 100 })
  dishName: string;

  /**
   * 菜品价格
   */
  @Column({ name: 'dish_price', type: 'decimal', precision: 10, scale: 2 })
  dishPrice: number;

  /**
   * 数量
   */
  @Column()
  quantity: number;

  /**
   * 小计金额
   */
  @Column({ type: 'decimal', precision: 10, scale: 2 })
  subtotal: number;

  /**
   * 备注
   */
  @Column({ length: 255, nullable: true })
  remark: string;

  /**
   * 规格信息，格式：[{group:"规格组名",option:"选项名"}]
   */
  @Column({ name: 'spec_values', type: 'json', nullable: true })
  specValues: any;

  /**
   * 创建时间
   */
  @CreateDateColumn({ name: 'create_time' })
  createTime: Date;
} 